package reflect;

import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test3 {
    public static void main(String[] args) throws Exception {
        File dir = new File(
                Test3.class.getResource(".").toURI()
        );
        String packname = Test3.class.getPackage().getName();
        String[] strings = dir.list();
        for (String string : strings) {
            String[] str = string.split("\\.");
            Class cls = Class.forName(packname + "." + str[0]);
            Object obj = cls.newInstance();
            Method[] methods = cls.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().contains("s") &&
                        methods[i].getParameterCount() == 0
                        && methods[i].getModifiers() == Modifier.PUBLIC) {
                     /*method.setAccessible(true);*/
                    methods[i].invoke(obj);
                   /* method.setAccessible(false);*/
                }
            }
        }

    }
}
